// 二叉树的生成
// https://blog.csdn.net/qq_41499782/article/details/108578166
function NodeTree(value){
    this.name = value;
    this.left = null;
    this.right = null;
}

let node = new NodeTree('a');
let tb = new NodeTree('b');
let tc = new NodeTree('c');
let td = new NodeTree('d');
let te = new NodeTree('e');
let tf = new NodeTree('f');
let tg = new NodeTree('g');

node.left = tb;
node.right = tc;
tb.left = td;
tb.right = te;
tc.left = tf;
tc.right = tg;

let prelist = []
// 前序遍历
function preOrder(node){
    if(!(node==null)){
        prelist.push(node.name);
        preOrder(node.left)
        preOrder(node.right)
    }   
}

let inList = []
// 中序
function inOrder(node){
    if(!(node == null)){
        inOrder(node.left)
        inList.push(node.name)
        inOrder(node.right)
    }
}


let afterList = []
// 后续
function afterOrder(node){
    if(!(node == null)){
        afterOrder(node.left)
        afterOrder(node.right)
        afterList.push(node.name)
    }
}

preOrder(node)
inOrder(node)
afterOrder(node)
console.log(prelist)
console.log(inList)
console.log(afterList)
